# config for vip-manager by Cybertec Schönig & Schönig GmbH

# time (in milliseconds) after which vip-manager wakes up and checks if it needs to register or release ip addresses.
interval: {{ vip_manager_interval }}

{% if vip_manager_dcs_type | default(dcs_type) == 'patroni' %}
trigger-key: "/leader"
trigger-value: 200
{% else %}
# the etcd or consul key which vip-manager will regularly poll.
trigger-key: "/{{ patroni_etcd_namespace | default('service') }}/{{ patroni_cluster_name }}/leader"
# if the value of the above key matches the trigger-value (often the hostname of this host), vip-manager will try to add the virtual ip address to the interface specified in Iface
trigger-value: "{{ ansible_hostname }}"
{% endif %}

ip: {{ vip_manager_ip }} # the virtual ip address to manage
netmask: {{ vip_manager_mask }} # netmask for the virtual ip
interface: {{ vip_manager_iface }} # interface to which the virtual ip will be added

# how the virtual ip should be managed. we currently support "ip addr add/remove" through shell commands or the Hetzner api
hosting-type: basic # possible values: basic, or hetzner.

dcs-type: {{ vip_manager_dcs_type | default(dcs_type) }} # etcd, consul or patroni

{% if vip_manager_dcs_type | default(dcs_type) == 'etcd' %}
# a list that contains all DCS endpoints to which vip-manager could talk.
{% if not dcs_exists | bool %}
dcs-endpoints:
{% for host in groups['etcd_cluster'] %}
  - {{ patroni_etcd_protocol | default('http', true) }}://{{ hostvars[host]['etcd_bind_address'] | default(hostvars[host]['bind_address'], true) }}:2379
{% endfor %}
{% else %}
dcs-endpoints:
{% for etcd_hosts in patroni_etcd_hosts %}
  - {{ patroni_etcd_protocol | default('http', true) }}://{{ etcd_hosts.host }}:{{ etcd_hosts.port }}
{% endfor %}
{% endif %}
{% endif %}
{% if vip_manager_dcs_type | default(dcs_type) == 'consul' %}
# A list that contains all DCS endpoints to which vip-manager could talk.
dcs-endpoints:
{% if not dcs_exists | bool %}
  {% if consul_client_address == '127.0.0.1' %}
  - http://127.0.0.1:8500
  {% else %}
  {% for host in groups['consul_instances'] %}
  - http://{{ hostvars[host]['consul_bind_address'] | default(hostvars[host]['bind_address'], true) }}:8500
  {% endfor %}
  {% endif %}
{% else %}
  {% for consul_host in consul_join %}
  - http://{{ consul_host }}:8500
  {% endfor %}
{% endif %}
{% if consul_token | default("") | length > 0 %}
consul-token: "{{ consul_token | default('') }}"
{% endif %}
{% endif %}

{% if vip_manager_dcs_type | default(dcs_type) == 'etcd' %}
{% if patroni_etcd_username | default("") | length > 0 %}
etcd-user: {{ patroni_etcd_username | default("") }}
{% endif %}
{% if patroni_etcd_password | default("") | length > 0 %}
etcd-password: {{ patroni_etcd_password | default("") }}
{% endif %}
{% if etcd_tls_enable | default(false) | bool %}
# when etcd-ca-file is specified, TLS connections to the etcd endpoints will be used.
etcd-ca-file: {{ patroni_etcd_cacert | default('/etc/patroni/tls/etcd/ca.crt') }}
# when etcd-cert-file and etcd-key-file are specified, we will authenticate at the etcd endpoints using this certificate and key.
etcd-cert-file: {{ patroni_etcd_cert | default('/etc/patroni/tls/etcd/server.crt') }}
etcd-key-file: {{ patroni_etcd_key | default('/etc/patroni/tls/etcd/server.key') }}
{% endif %}
{% endif %}

# how often things should be retried and how long to wait between retries. (currently only affects arpClient)
retry-num: 2
retry-after: 250  # in milliseconds

# verbose logs (currently only supported for hetzner)
verbose: false
